function [ydu, xdu, breakss] = varprior_h(nv,nlags,nex,hyp,premom)
%function [ydu, xdu, breakss] = varprior_h(nv,nlags,nex,hyp,premom)
% Inputs:
%  - nv: number of variables
%  - nlags: number of lags
%  - nex: number of exogenous variables including intercept
%  - hyp: vector of hyperparameters
%  - premom: pre-sample moments [mean; std]
% Outputs:
%  - ydu: dummy variables for dependent variables 
%  - xdu: dummy variables for independent variables 
%  - breakss: break points between different dummy elements

% Based on replication codes for Dario Caldara and Christophe Kamps (2017), The Analytics of SVARs: A
% Unified Framework to Measure Fiscal Multipliers, Review of Economic Studies (2017) 84, 1015–1040
%
% Copyright: 2017 Dario Caldara and Christophe Kamps
% Copyright: 2020-2023 Benjamin Born, Francesco D'Ascanio, Gernot J. Mueller, Johannes Pfeifer


tau = hyp(1,:); %lambda_1 in Del Negro/Schorfheide 2010 Handbook Chapter
dd = hyp(2,:); %lambda_2 in DS2010
ww = hyp(3,:); %lambda_3 in DS2010
lam = hyp(4,:); %lambda_5 in DS2010
mm = hyp(5,:); %lambda_4 in DS2010

% initializations
dsize = nex + (nlags+ww+1)*nv;
breakss = zeros(5,1);
ydu = zeros(dsize,nv);
xdu = zeros(dsize,nv*nlags+nex);

% dummies for the coefficients of the first lag, equation (9) of DS2010
sig = diag(premom(:,2));
ydu(1:nv,:) = tau*sig;
xdu(1:nv,:) = [tau*sig zeros(nv,(nlags-1)*nv+nex)];
breakss(1) = nv;

% dummies for the coefficients of the remaining lags, equation (10) of DS2010
if nlags > 1
    ydu(breakss(1)+1:nv*nlags,:) = zeros((nlags-1)*nv,nv);
    j = 1;
    while j <= nlags-1
        xdu(breakss(1)+(j-1)*nv+1:breakss(1)+j*nv,:) = [zeros(nv,j*nv) tau*sig*((j+1)^dd) zeros(nv,(nlags-1-j)*nv+nex)];
        j = j+1;
    end % while
    breakss(2) = breakss(1)+(nlags-1)*nv;
else
    breakss(2) = breakss(1);
end % if

% dummies for the covariance matrix of error terms, equation (11) of DS2010
ydu(breakss(2)+1:breakss(2)+ww*nv,:) = kron(ones(ww,1),sig);
breakss(3) = breakss(2)+ww*nv;

% dummies for the coefficents of the constant term, equation (13) of DS2010
lammean = lam*premom(:,1)';
ydu(breakss(3)+1,:) = lammean;
xdu(breakss(3)+1,:) = [kron(ones(1,nlags),lammean) lam];
breakss(4) = breakss(3)+1;

% dummies for the covariance matrix of coefficients of different lags,
% equation (12)
mumean = diag(mm*premom(:,1));
ydu(breakss(4)+1:breakss(4)+nv,:) = mumean;
xdu(breakss(4)+1:breakss(4)+nv,:) = [kron(ones(1,nlags),mumean) zeros(nv,nex)];
breakss(5) = breakss(4)+nv;